package adminLoginPack;

import java.io.FileInputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import ImmovableIndia.serviceManagerImpl;
import Notifications.notificationsDataLoading;

public class UiFrontPageAction extends Action {
 
	private static final Logger logger = Logger.getLogger(UiFrontPageAction.class);
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
 
       String mappingValue  ="";
       String userName = "";
       String password = "";
       String method = "";
       String addUsrMethod = "";
       boolean admin = false;
       FileInputStream fis ;
       
       try{
    	   String path = request.getSession().getServletContext().getRealPath("/webDefault");
    	   fis  = new FileInputStream(path+"/aboutUs.html");
           password = (String)request.getParameter("password");
           method = (String)request.getParameter("method123");
           
           String adminValue = null != request.getParameter("admin")?(String)request.getParameter("admin"):"N";
           userName = null != request.getParameter("userId")?(String)request.getParameter("userId"):"N";
           
           addUsrMethod= (String)request.getParameter("METHOD1234");
           if(null == method && "".equals(method))
           method = null != request.getParameter("a")?request.getParameter("a"):"";
           
           String mainmethod123 = null != request.getParameter("mainmethod123")?(String)request.getParameter("mainmethod123"):"N";
           
           String UserIDForservice = null != request.getParameter("UserIDForservice")?(String)request.getParameter("UserIDForservice"):"";
           
           String applicationUserPage = null != request.getParameter("applicationUserPage")?(String)request.getParameter("applicationUserPage"):"";
           
          if(!"applicationUserPage".equals(applicationUserPage)) {
           
	   if(null != method && method.equals("logout")){
    	   
    	   request.getSession().invalidate();
    	   mappingValue = "authfailiure";
    	  
       }else  if(null != method && method.equals("newReg")){
    	   
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("DatePic", "YES");
    	   
    	   request.setAttribute("ShowUiPage", "/webDefault/UserInformation.jsp");
    	  
    	   mappingValue ="success";
       
       }else  if(null != method && method.equals("forgotPassword")){
    	   
    	   request.setAttribute("userForgot", "userForgot");
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("ShowUiPage", "/webDefault/ForgotPassword.jsp");
    	   mappingValue ="success";
       }else  if(null != method && method.equals("changePassword")){
    	   request.setAttribute("changePassword", "changePassword");
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("ShowUiPage", "/webDefault/ForgotPassword.jsp");
    	   mappingValue ="success";
       
       }else  if(null != method && method.equals("updateProfile")){
    	   notificationsDataLoading notificationDL = new notificationsDataLoading();
    	   request.setAttribute("showUserPage", "UserPage");
    	   List userList = notificationDL.getUserData(userName, "investment_user1"); 
    	   request.setAttribute("ShowUiPage", "/UpdateuserInformation.jsp");
    	   request.setAttribute("UserInformation", userList);
    	   mappingValue ="success";
       
       }else  if(null != method && method.equals("contactus")){
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("title", "Contact Us");
    	   request.setAttribute("ShowUiPage", "/webDefault/ContactUs.jsp");
    	  
    	   mappingValue ="success";
    	   
    	   
    	   
       }else  if(null != method && (method.equals("Postyour") || method.equals("newsletter"))){
    	   
    	   request.setAttribute("showUserPage", "UserPage");
    	   
    	   request.setAttribute("ShowUiPage", "/webDefault/newsPosturqueries.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && method.equals("aboutus")){
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("title", "About Us");
    	   request.setAttribute("ShowUiPage", "/webDefault/aboutUs.html");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && method.contains("services")){
    	   String [] array = method.split("~");
    	   if(array.length>=2){
    	   String setting =  array[1];
    	   System.out.println("This is service header name----->"+array[1]);
    	   request.setAttribute("innerService", array[1]);
    	   if(array[1].equalsIgnoreCase("Structuring")){
    		   request.setAttribute("title", "Structuring");
    	   }else if(array[1].equalsIgnoreCase("Equity")){
    		   request.setAttribute("title", "Capital & Equity");
    	   }else if(array[1].equalsIgnoreCase("Debt")){
    		   request.setAttribute("title", "Debt");
    	   }else if(array[1].equalsIgnoreCase("INCAT")){
    		   request.setAttribute("title", "Inbound Current Account Transactions");
    	   }else if(array[1].equalsIgnoreCase("others")){
    		   request.setAttribute("title", "Setting Up Of A BO, LO, PO In India");
    	   }else if(array[1].equalsIgnoreCase("OBEquityDebit")){
    		   request.setAttribute("title", "Equity & Debt");
    	   }else if(array[1].equalsIgnoreCase("OBOCAT")){
    		   request.setAttribute("title", "Outbound Current Account Transactions");
    	   }else if(array[1].equalsIgnoreCase("OBothers")){
    		   request.setAttribute("title", "Setting Up Of A Branch, Posting Representative Office Abroad");
    	   }else if(array[1].equalsIgnoreCase("Due")){
    		   request.setAttribute("title", "Due Diligence");
    	   }else if(array[1].equalsIgnoreCase("SFOI")){
    		   request.setAttribute("title", "Setting Up Of Offices In India");
    	   }else if(array[1].equalsIgnoreCase("SFOUTSIDEI")){
    		   request.setAttribute("title", "Setting Up Of Offices Outside India");
    	   }else if(array[1].equalsIgnoreCase("SCII")){
    		   request.setAttribute("title", "Setting Up Compliances In India");
    	   }else if(array[1].equalsIgnoreCase("CFDOII")){
    		   request.setAttribute("title", "Compliances For Different Offices In India");
    	   }
    	   }
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("ListType", "services");
    	   request.setAttribute("ShowUiPage", "/webDefault/Service.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && method.contains("Postyour")){
    	   String [] array = method.split("~");
    	   if(array.length>=2){
    	   String setting =  array[1];
    	   
    	   request.setAttribute("innerService", array[1]);
    	   if(array[1].equalsIgnoreCase("suooii")){
    		   request.setAttribute("title", "BO/PO/LO In India");
    	   }else if(array[1].equalsIgnoreCase("compouund")){
    		   request.setAttribute("title", "Compounding Of Offences");
    	   }else if(array[1].equalsIgnoreCase("IBIP")){
    		   request.setAttribute("title", "Investment By Indian Parties In JV/ WOS (ODI)");
    	   }else if(array[1].equalsIgnoreCase("PRIIIFS")){
    		   request.setAttribute("title", "ODI Individual");
    	   }else if(array[1].equalsIgnoreCase("IIISN")){
    		   request.setAttribute("title", "Foreign Direct Investment");
    	   }else if(array[1].equalsIgnoreCase("IIIS")){
    		   request.setAttribute("title", "Foreign Direct Investment - Transfer");
    	   }else if(array[1].equalsIgnoreCase("BDIR")){
    		   request.setAttribute("title", "Borrowing / Deposits In Rupees");
    	   }else if(array[1].equalsIgnoreCase("FER")){
    		   request.setAttribute("title", "Foreign Exchange Remittance");
    	   }else if(array[1].equalsIgnoreCase("EOGAS")){
    		   request.setAttribute("title", "Export Of Goods And Services");
    	   }else if(array[1].equalsIgnoreCase("IOGAS")){
    		   request.setAttribute("title", "Import Of Goods And Services");
    	   }else if(array[1].equalsIgnoreCase("BOOA")){
    		   request.setAttribute("title", "Branch or Office Abroad");
    	   }else if(array[1].equalsIgnoreCase("IPOI")){
    		   request.setAttribute("title", "Immovable Property Outside India");
    	   }else if(array[1].equalsIgnoreCase("IPII")){
    		   request.setAttribute("title", "Immovable Property In India");
    	   }else if(array[1].equalsIgnoreCase("ECB")){
    		   request.setAttribute("title", "External Commercial Borrowing");
    	   }
    	   }
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("ListType", "queries");
    	   request.setAttribute("ShowUiPage", "/webDefault/newsPosturqueries.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && method.contains("Opportunities")){
    	   String [] array = method.split("~");
    	   if(array.length>=2){
    	   String setting =  array[1];
    	   
    	   request.setAttribute("innerService", array[1]);
    	   }
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("title", "Opportunities");
    	   request.setAttribute("ShowUiPage", "/webDefault/Opportunities.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && (method.contains("support") )){
    	   
    	   request.setAttribute("innerService", method);
    	   request.setAttribute("showUserPage", "UserPage");
    	   request.setAttribute("title", "SUPPORT");
    	   request.setAttribute("ShowUiPage", "/webDefault/defaultPage.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else  if(null != method && (method.contains("withoutUser") )){
    	   
    	   request.setAttribute("innerService", method);
    	   
    	   request.setAttribute("showUserPage", "UserPage");
    	   
    	   request.setAttribute("ShowUiPage", "/webDefault/defaultPage.jsp");
    	  
    	   mappingValue ="success";
    	   
       }else{
    	   
    	   mappingValue ="success";
       }
       if(null != addUsrMethod && addUsrMethod.equals("AddUser")){
    	   
    	   
       }
       
       
       if(null != UserIDForservice && !"".equals(UserIDForservice) && !"null".equals(UserIDForservice)){/*
    	  String str = ""; 
    	  if(UserIDForservice.trim().equals("newReg")){
   			  fis  = new FileInputStream(path+"/UserInformation.jsp");
   		  }else if(UserIDForservice.trim().equals("contactus")){
   			  fis  = new FileInputStream(path+"/ContactUs.jsp");
   		  }else if(UserIDForservice.trim().equals("Postyour") ){
   			serviceManagerImpl smp = new serviceManagerImpl();
   			str = smp.getWithoutUserData();
   		  }else if(UserIDForservice.trim().equals("aboutus")){
   			  fis  = new FileInputStream(path+"/aboutUs.html");
   		  }else if(UserIDForservice.trim().equals("services")){
   			  fis  = new FileInputStream(path+"/Service.jsp");
   		  }else if(UserIDForservice.trim().equals("contactus")){
   			  fis  = new FileInputStream(path+"/ContactUs.jsp");
   		  }
    	   
		  if(!UserIDForservice.trim().equals("Postyour") && !UserIDForservice.trim().equals("newsletter")){
			      try {
			           int content;
			          while ((content = fis.read()) != -1) {
			              // convert to char and display it
			              str += (char) content;
			          }
			      }catch(Exception e){
			    	  System.out.println(e);
			      }
		  }
          System.out.println(str);
          response.getWriter().write(str); 
          
          mappingValue =null;
       */}
       
       }else {
    	   
    	   String id = null != request.getParameter("id")?(String)request.getParameter("id"):"";
    	   
    	   if(null != id){
    		   if(id.equals("contactus")){
    			   mappingValue = "contactus";
    			   request.setAttribute("title", "Contact Us");
    		   }else if(id.equals("newReg")){
    			   mappingValue = "newreg";
    		   }else if(id.contains("services")){
    			   String [] array = id.split("~");
    	    	   if(array.length>=2){
    	    	   String setting =  array[1];
    	    	   System.out.println("This is service header name---->:"+array[1]);
    	    	   request.setAttribute("innerService", array[1]);
    	    	   if(array[1].equalsIgnoreCase("Structuring")){
    	    		   request.setAttribute("title", "Structuring");
    	    	   }else if(array[1].equalsIgnoreCase("Equity")){
    	    		   request.setAttribute("title", "Capital & Equity");
    	    	   }else if(array[1].equalsIgnoreCase("Debt")){
    	    		   request.setAttribute("title", "Debt");
    	    	   }else if(array[1].equalsIgnoreCase("INCAT")){
    	    		   request.setAttribute("title", "Inbound Current Account Transactions");
    	    	   }else if(array[1].equalsIgnoreCase("others")){
    	    		   request.setAttribute("title", "Setting Up Of A BO, LO, PO In India");
    	    	   }else if(array[1].equalsIgnoreCase("OBEquityDebit")){
    	    		   request.setAttribute("title", "Equity & Debt");
    	    	   }else if(array[1].equalsIgnoreCase("OBOCAT")){
    	    		   request.setAttribute("title", "Outbound Current Account Transactions");
    	    	   }else if(array[1].equalsIgnoreCase("OBothers")){
    	    		   request.setAttribute("title", "Setting Up Of A Branch, Posting Representative Office Abroad");
    	    	   }else if(array[1].equalsIgnoreCase("Due")){
    	    		   request.setAttribute("title", "Due Diligence");
    	    	   }else if(array[1].equalsIgnoreCase("SFOI")){
    	    		   request.setAttribute("title", "Setting Up Of Offices In India");
    	    	   }else if(array[1].equalsIgnoreCase("SFOUTSIDEI")){
    	    		   request.setAttribute("title", "Setting Up Of Offices Outside India");
    	    	   }else if(array[1].equalsIgnoreCase("SCII")){
    	    		   request.setAttribute("title", "Setting Up Compliances In India");
    	    	   }else if(array[1].equalsIgnoreCase("CFDOII")){
    	    		   request.setAttribute("title", "Compliances For Different Offices In India");
    	    	   }
    	    	   }
    	    	   request.setAttribute("showUserPage", "UserPage");
    	    	   request.setAttribute("ListType", "services");
    	    	   request.setAttribute("ShowUiPage", "/webDefault/Service.jsp");
    			   mappingValue = "services";
    		   }else if(id.contains("support")){
    	    	   String [] array = id.split("~");
    	    	   if(array.length>=2){
    	    	   String setting =  array[1];
    	    	   request.setAttribute("innerService", array[1]);
    	    	   }
    	    	   request.setAttribute("innerService", id);
    	    	   request.setAttribute("showUserPage", "UserPage");
    	    	   request.setAttribute("title", "Support");
    	    	   request.setAttribute("ShowUiPage", "/webDefault/defaultPage.jsp");
    	    	   mappingValue ="support";
    			   
    		   }else if(id.contains("Opportunities")){
    		
    			   String [] array = id.split("~");
    	    	   if(array.length>=2){
    	    	   String setting =  array[1];
    	    	   
    	    	   request.setAttribute("innerService", array[1]);
    	    	   }
    	    	   request.setAttribute("showUserPage", "UserPage");
    	    	   request.setAttribute("title", "Opportunities");
    	    	   request.setAttribute("ShowUiPage", "/webDefault/Opportunities.jsp");
    	    	   
    	    	   mappingValue ="Opportunities";
    	    	  
    		   }else if(id.contains("Postyour")){
    			   String [] array = id.split("~");
    	    	   if(array.length>=2){
    	    	   String setting =  array[1];
    	    	   
    	    	   request.setAttribute("innerService", array[1]);
    	    	   if(array[1].equalsIgnoreCase("suooii")){
    	    		   request.setAttribute("title", "BO/PO/LO In India");
    	    	   }else if(array[1].equalsIgnoreCase("compouund")){
    	    		   request.setAttribute("title", "Compounding Of Offences");
    	    	   }else if(array[1].equalsIgnoreCase("IBIP")){
    	    		   request.setAttribute("title", "Investment By Indian Parties In JV/ WOS (ODI)");
    	    	   }else if(array[1].equalsIgnoreCase("PRIIIFS")){
    	    		   request.setAttribute("title", "ODI Individual");
    	    	   }else if(array[1].equalsIgnoreCase("IIISN")){
    	    		   request.setAttribute("title", "Foreign Direct Investment");
    	    	   }else if(array[1].equalsIgnoreCase("IIIS")){
    	    		   request.setAttribute("title", "Foreign Direct Investment - Transfer");
    	    	   }else if(array[1].equalsIgnoreCase("BDIR")){
    	    		   request.setAttribute("title", "Borrowing / Deposits In Rupees");
    	    	   }else if(array[1].equalsIgnoreCase("FER")){
    	    		   request.setAttribute("title", "Foreign Exchange Remittance ");
    	    	   }else if(array[1].equalsIgnoreCase("EOGAS")){
    	    		   request.setAttribute("title", "Export Of Goods And Services");
    	    	   }else if(array[1].equalsIgnoreCase("IOGAS")){
    	    		   request.setAttribute("title", "Import Of Goods And Services");
    	    	   }else if(array[1].equalsIgnoreCase("BOOA")){
    	    		   request.setAttribute("title", "Branch or Office Abroad");
    	    	   }else if(array[1].equalsIgnoreCase("IPOI")){
    	    		   request.setAttribute("title", "Immovable Property Outside India");
    	    	   }else if(array[1].equalsIgnoreCase("IPII")){
    	    		   request.setAttribute("title", "Immovable Property In India");
    	    	   }else if(array[1].equalsIgnoreCase("ECB")){
    	    		   request.setAttribute("title", "External Commercial Borrowing");
    	    	   }
    	    	   }
    	    	   request.setAttribute("showUserPage", "UserPage");
    	    	   
    	    	   request.setAttribute("ShowUiPage", "/webDefault/newsPosturqueries.jsp");
    	    	   mappingValue = "postyour";
    	    	  
    		   }else if(id.equals("aboutus")){
    			   mappingValue = "aboutus";
    			   request.setAttribute("title", "About Us");
    			   
    		   }
    		   
    	   }
    	   
    	   
    	   
    	   
    	   
    	   
       }
       
       
       
       
       }catch(Exception e){
    	   e.printStackTrace();
    	   response.getWriter().write("Source file was not found"); 
       }
       
      
       
       
       return mapping.findForward(mappingValue);
 
    }
 
}


